using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class TemporaryBonus{
	public string toStat = "Strength";
	public string subStat = "None";
	
	public int amount
	{
		get
		{
			return (int)MathParser.Evaluate(_amount);
		}
		set
		{
			_amount = value.ToString();
		}
	}
	
	public string _amount = "4";
	public int dicep = 0;
	public string type = "Misc.";
	public LoadableJSONObject originator;
	
	public TemporaryBonus()
	{

	}
	
	public string GetDescription()
	{
		return ((dicep > 0)?(dicep + "d"):((amount > 0)?("+"):(""))) + amount + " " + toStat + (subStat == "None"?"":" ("+subStat+")") + ((type != "Not A")?" [" + type + "]":"");
	}
	
	public void LoadFromJSON(string json, LoadableJSONObject origin)
	{
		Dictionary<string,string> jDict = (MiniJSON.Json.Deserialize(json) as Dictionary<string,object>).ToDSS();
		toStat = jDict["toStat"];
		_amount = jDict["amount"];
		//isMultiplier = bool.Parse(jDict["toStat"]);
		type = jDict["type"];
		dicep = int.Parse(jDict["dicep"]);
		
		if(jDict.ContainsKey("subStat"))
		{
			subStat = jDict["subStat"];
		}
		
		originator = origin;
	}
	
	public string ToJSON()
	{
		Dictionary<string,string> jDict = new Dictionary<string, string>();
		jDict.Add("toStat", toStat.ToString());
		jDict.Add("amount", _amount);
		//jDict.Add("isMultiplier", isMultiplier.ToString());
		jDict.Add("type", type.ToString());
		jDict.Add("dicep", dicep.ToString());
		jDict.Add("subStat", subStat);
		
		return MiniJSON.Json.Serialize(jDict);
	}
}
